<template>
  <div class="goods-comment-image">
    <div class="list">
      <a href="javascript:;" :class="{active:currImage===i}" @click="currImage=i" v-for="(url, i) in pictures" :key="i">
        <img :src="url" alt="">
      </a>
    </div>
    <div class="preview" v-if="currImage !== null">
      <img :src="pictures[currImage]" alt="">
      <span @click="currImage--" class="prev iconfont icon-angle-left" v-if="currImage !== 0"></span>
      <span @click="currImage++" class="next iconfont icon-angle-right" v-if="currImage !== (pictures.length - 1)"></span>
      <i @click="currImage=null" class="iconfont icon-guanbi"></i>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue'
export default {
  name: 'GoodsCommentImage',
  props: {
    pictures: {
      type: Array,
      default: () => []
    }
  },
  setup () {
    const currImage = ref(null)
    return { currImage }
  }
}
</script>

<style lang="less" scoped>
.goods-comment-image {
  .list {
    display: flex;
    flex-wrap: wrap;
    margin-top: 10px;
    a {
      width: 120px;
      height: 120px;
      border:1px solid #e4e4e4;
      margin-right: 20px;
      margin-bottom: 10px;
      img {
        width: 100%;
        height: 100%;
        object-fit: contain;
      }
      &.active {
        border-color: @xtxColor;
      }
    }
  }
  .preview {
    width: 680px;
    height: 600px;
    border: 1px solid #e4e4e4;
    background: #000000;
    margin-bottom: 20px;
    position: relative;
    img {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }
    // 切换按钮
    .prev,.next {
      width: 44px;
      height: 44px;
      line-height: 44px;
      text-align: center;
      border-radius: 50%;
      margin-top: -22px;
      opacity: 0;
      transition: opacity 0.5s;
      background-color: rgba(0, 0, 0, 0.3);
      position: absolute;
      top: 50%;
      color: #f5f5f5;
      font-size: 20px;
      &.prev {
        left: 10px;
      }
      &.next {
        right: 10px;
      }
    }
    &:hover {
      .prev, .next {
        opacity: 1;
      }
    }
    i {
      position: absolute;
      right: 0;
      top: 0;
      width: 30px;
      height: 30px;
      background: rgba(0,0,0,0.2);
      color: #fff;
      text-align: center;
      line-height: 30px;
    }
  }
}
</style>
